//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#if !defined(__CREADERWRITERLOCK_H__)
#define __CREADERWRITERLOCK_H__

class CReaderWriterLock : public IReaderWriterLock
{
// Interface functions
//
public:
    CARAPI_(PInterface) Probe(
        /* [in] */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Aggregate(
        /* [in] */ AggrType aggrType,
        /* [in] */ PInterface pObject);

    CARAPI GetDomain(
        /* [out] */ PInterface *ppObject);

    CARAPI ReaderLock(
        /* [out] */ WaitResult *pResult);

    CARAPI ReaderTryLock(
        /* [in] */ Millisecond32 msTimeout,
        /* [out] */ WaitResult *pResult);

    CARAPI ReaderUnlock();

    CARAPI UpgradeToWriter(
        /* [out] */ WaitResult *pResult);

    CARAPI TryUpgradeToWriter(
        /* [in] */ Millisecond32 msTimeout,
        /* [out] */ WaitResult *pResult);

    CARAPI WriterLock(
        /* [out] */ WaitResult *pResult);

    CARAPI WriterTryLock(
        /* [in] */ Millisecond32 msTimeout,
        /* [out] */ WaitResult *pResult);

    CARAPI WriterUnlock();

    CARAPI DowngradeFromWriter();

    CARAPI IsReaderLockHeld(
        /* [out] */ Boolean *pIsHeld);

    CARAPI IsWriterLockHeld(
        /* [out] */ Boolean *pIsHeld);

    virtual ~CReaderWriterLock() {}
private:
    Interlocked m_cRef;
    RWLock m_krwlock;
};

#endif //!(__CREADERWRITERLOCK_H__)
